<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template.xhtml">

	<ui:define name="head">
		<script type="text/javascript">
			function handleDrop(event, ui) {
				var droppedCar = ui.draggable;

				droppedCar.fadeOut('fast');
			}
			function handleInstockClose() {
					instockDialog.hide();
			}
			function handleInstockOpen() {
					instockDialog.show();
			}
		</script>
	</ui:define>
	<ui:define name="content">
		<p:ajaxStatus onstart="modalDialogTest.show();"
			onsuccess="modalDialogTest.hide();" />
		<p:dialog id="modalDialog" showHeader="false"
			widgetVar="modalDialogTest" modal="true">
			<p:graphicImage value="/images/478.gif" />
		</p:dialog>

		<h:form id="form2">
		 <p:growl id="growlInstock_Id" showDetail="true"  />  
			<p:dataTable id="instockId" var="instock"
				value="#{mbInStock.instocks}" rowIndexVar="rowIndex"
				selection="#{mbInStock.selectedInStocks}" paginator="true" rows="10"
				rowKey="#{instock.instockId}"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				rowsPerPageTemplate="5,10,15" paginatorPosition="bottom">
				<p:ajax event="rowSelectCheckbox" update=":form2:instockId">
				</p:ajax>
				<f:facet name="header">
					<h:panelGrid columns="7" style="float:left;width:40%">
						<p:inputText />
						<h:outputText value="Từ ngày:" />
						<p:inputText style="width:100px;" />
						<h:outputText value="Đến ngày:" />
						<p:inputText style="width:100px;" />
						<p:commandButton value="Tìm kiếm" icon="ui-icon-search" />
					</h:panelGrid>


				</f:facet>
				<p:column selectionMode="multiple" style="width:2%" />
				<p:column headerText="STT" style="width:3%">
					<h:outputText value="#{rowIndex+1}" />
				</p:column>
				<p:column headerText="Mã phiếu nhập" sortBy="#{instock.instockCode}">
					<h:outputText value="#{instock.instockCode}" />
				</p:column>

				<p:column headerText="Ngày tạo" sortBy="#{instock.dateCreated}">
					<h:outputText value="#{instock.dateCreated}" />

				</p:column>

				<p:column headerText="Số chứng từ">
					<h:outputText value="#{instock.docCode}" />
				</p:column>
				<p:column headerText="Ghi chú">
					<h:outputText value="#{instock.note}" />
				</p:column>
				<f:facet name="footer">
					<p:commandButton value="Thêm mới" icon="ui-icon-plus"
						style="float:left;" actionListener="#{mbInStock.loadInfoToAdd}"
						update=":form2:geInfoId,:form2:goodInfoId" oncomplete="instockDialog.show();" />

					<p:commandButton value="Sửa" icon="ui-icon-pencil"
						style="float:left;" update=":form2:display2"
						oncomplete="instockDialogVar.show()"
						disabled="#{mbInStock.selectedInStocks == null}" />

					<p:commandButton value="Xóa" icon="ui-icon-cancel"
						style="float:left;" update=":form2:display2"
						oncomplete="carDialog2.show()"
						disabled="#{mbInStock.selectedInStocks == null}" />

					<p:commandButton value="In phiếu" icon="ui-icon-print"
						style="float:left;" update=":form2:display2"
						disabled="#{mbInStock.selectedInStocks == null}"
						oncomplete="carDialog2.show()" />
				</f:facet>
			</p:dataTable>

			<p:dialog header="Thông tin phiếu nhập kho"
				widgetVar="instockDialogVar" id="instockDialogID" width="250"
				showEffect="fade" hideEffect="fade">

				<p:dataList id="display2" value="#{mbInStock.selectedInStocks}"
					var="selectedIS" type="definition">

					<h:outputText value="#{selectedIS.instockCode}" />
				</p:dataList>

			</p:dialog>
			<p:dialog header="THÊM PHIẾU NHẬP KHO" widgetVar="instockDialog"
				modal="true" width="800" height="600" showEffect="fade"
				hideEffect="fade">
				<p:spacer height="20" />
				<h:outputText value="THÔNG TIN CHUNG" />
				<p:fieldset style="width:97%;">
					<h:panelGrid id="geInfoId" columns="4" style="width:97%;">
						<h:outputText value="Mã phiếu nhập" />
						<p:inputText value="#{mbInStock.instock.instockCode}"
							style="width:180px;" disabled="true" />

						<h:outputText value="Số chứng từ(*)" />
						<p:inputText value="#{mbInStock.instock.docCode}" />

						<h:outputText value="Ngày chứng từ(*)" />
						<p:calendar effect="fadeIn" pattern="dd-MM-yyyy"
							value="#{mbInStock.instock.instockDate}" />
						<h:outputText value="Người giao hàng(*)" />
						<p:inputText style="width:180px;"
							value="#{mbInStock.instock.deliveryBy}" />

						<h:outputText value="Người lập phiếu(*)" />
						<p:selectOneMenu value="#{mbInStock.instock.former}">
							<f:selectItem itemLabel="--------Chọn---------" itemValue="" />
							<f:selectItems value="#{mbInStock.mapEmployees}" />
						</p:selectOneMenu>

					</h:panelGrid>
				</p:fieldset>
				<p:spacer height="20" />
				<h:outputText value="CHI TIẾT HÀNG HÓA" />
				<p:fieldset style="width:97%;">
					<h:panelGrid id="goodInfoId" columns="4" border="0"
						style="width:97%;">
						<h:outputText value="Tên hàng(*)" />
						<p:selectOneMenu value="#{mbInStock.goodsTmp.goodsId}">
							<f:selectItem itemLabel="--------Chọn---------" itemValue="0" />
							<f:selectItems value="#{mbInStock.mapGoods}" />
							<p:ajax update=":form2:goodInfoId" event="change"
								listener="#{mbInStock.valueChanged}" />
						</p:selectOneMenu>
						<h:outputText value="Mã hàng(*)" />
						<p:inputText value="#{mbInStock.goodsTmp.goodsCode}" />

						<h:outputText value="Ðon vị(*)" />
						<p:selectOneMenu value="#{mbInStock.goodsTmp.unitId}">
							<f:selectItem itemLabel="--------Chọn---------" itemValue="0" />
							<f:selectItems value="#{mbInStock.mapUnits}" />
						</p:selectOneMenu>
						<h:outputText value="Đơn giá(*)" />
						<p:inputText value="#{mbInStock.goodsTmp.unitPrice}">
							<f:convertNumber type="number" groupingUsed="true"
								maxFractionDigits="2" pattern="###,###,###,###" />
						</p:inputText>
						<h:outputText value="Số lượng(*)" />
						<p:inputText value="#{mbInStock.goodsTmp.quantity}">
							<f:convertNumber type="number" groupingUsed="true"
								maxFractionDigits="2" pattern="###,###,###,###" />
						</p:inputText>
						<h:panelGrid style="width:20%;" columns="2">
							<p:commandButton value="Thêm" icon="ui-icon-plus"
								actionListener="#{mbInStock.addGoodsToInstock}"
								update=":form2:dtllistGoodsId,:form2:messagesInstock_Id" />

						</h:panelGrid>
						<p:commandButton value="Import" icon="ui-icon-plus" />
					</h:panelGrid>


					<h:panelGrid style="width:97%;">
						<p:dataTable id="dtllistGoodsId" value="#{mbInStock.goodsTmps}"
							rowIndexVar="rowIndex" var="egood" style="width:100%;"
							rowKey="#{egood.goodsCode}" emptyMessage="Không có sản phẩm nào"
							selection="#{mbInStock.goodsTmpsArray}">
							<f:facet name="header">
								<h:outputText value="Hàng hóa được thêm vào" style="float:left;" />
							</f:facet>
							<p:column selectionMode="multiple" style="width:2%" />
							<p:column headerText="STT" style="width:5%;">
								<h:outputText value="#{rowIndex+1}" />
							</p:column>

							<p:column headerText="Mã hàng">
								<h:outputText value="#{egood.goodsCode}" />
							</p:column>

							<p:column headerText="Tên hàng">
								<h:outputText value="#{egood.goodsName}" />
							</p:column>

							<p:column headerText="Ðon vị" style="width:5%;">
								<h:outputText value="#{egood.unitCode}" />
							</p:column>
							<p:column headerText="Số lượng">
								<h:outputText value="#{egood.quantity}">
									<f:convertNumber type="number" groupingUsed="true"
										maxFractionDigits="2" pattern="###,###,###,###" />
								</h:outputText>
							</p:column>
							<p:column headerText="Thành tiền">
								<h:outputText value="#{egood.total}">
									<f:convertNumber type="number" groupingUsed="true"
										maxFractionDigits="2" pattern="###,###,###,###" />
								</h:outputText>
							</p:column>

							<f:facet name="footer">
								<p:commandLink style="float:left;color:blue;" actionListener="#{mbInStock.removeGoodsFromInstock}" update=":form2:dtllistGoodsId">
									<h:outputText value="Loại bỏ" />
								</p:commandLink>
								<h:outputText style="float:right;"
									value="#{mbInStock.instock.grandTotal}">
									<f:convertNumber type="number" groupingUsed="true"
										maxFractionDigits="2" pattern="###,###,###,###" />
								</h:outputText>
								<h:outputText value="Tổng cộng:" style="float:right;" />
							</f:facet>
						</p:dataTable>
					</h:panelGrid>
					<h:panelGrid id="stockInfoId" columns="2" style="width:80%;">
						<h:outputText value="Kho lưu trữ(*)" />
						<p:selectOneMenu value="#{mbInStock.stock.stockId}">
							<f:selectItem itemLabel="--------Chọn---------" itemValue="0" />
							<f:selectItems value="#{mbInStock.mapStocks}" />
						</p:selectOneMenu>
					</h:panelGrid>
					<h:panelGrid id="noteInfoId" columns="2" style="width:100%;">
						<h:outputText value="Ghi chú" />
						<p:inputTextarea rows="3" cols="90"
							value="#{mbInStock.instock.note}" />
					</h:panelGrid>
				</p:fieldset>
				<h:panelGrid id="buttonBarId" columns="5" border="0"
					style="width:100%;">
					<p:column>
						<h:outputText value="(*) thông tin bắt buộc" />
					</p:column>
					<p:column>

						<p:commandButton value="Ðóng" icon="ui-icon-close"
							oncomplete="instockDialog.hide();" style="float:right;" />
						<p:commandButton value="In phiếu" icon="ui-icon-print"
							style="float:right;" />
						<p:commandButton value="Làm lại" icon="ui-icon-refresh"
							style="float:right;" />
						<p:commandButton value="Lưu" icon="ui-icon-disk"
							actionListener="#{mbInStock.testGoodsInstock}"
							update=":form2:instockId,:form2:geInfoId,:form2:dtllistGoodsId,:form2:growlInstock_Id"
							oncomplete="instockDialog.hide();" style="float:right;" />
					</p:column>
				</h:panelGrid>
				<p:messages id="messagesInstock_Id" showDetail="true" autoUpdate="true" closable="true" />
			</p:dialog>

		</h:form>
	</ui:define>
</ui:composition>